define(function (require) {
    require('validate');
    var Base = require('group/common/main');
    var utils = require('common/utils/home');

    var Mask = require('common/mask');
    var mask = new Mask();

    return Base.extend({
        initialize: function (params) {
            var _this = this;
            Base.prototype.initialize.apply(this, [params]);
            if (_this['page_' + _global.a]) {
                _this['page_' + _global.a]();
            }
        },
        page_index: function () {
            var _this = this;
            $('#confirm').click(function(){
                var yi_id = $(this).attr('data-id');
                //if(window.confirm('是否确认收货？')){
                    utils.ajaxPost(_.extend({"yi_id": yi_id}, {m: 'yi_order', a: 'confirm_receipt'}), function (resp) {
                        if(resp.status == 1){
                            mask.success(resp.msg);
                            setTimeout(
                                _this.redirect(_.U({m: 'yi_order', a: 'index'}), 1)
                            ,2000);
                        } else {
                            mask.error(resp.msg);
                        }
                        
                    });
                //}
            });
            $('#view').click(function() {
                var id = $(this).attr('data-id');
                utils.ajaxPost(_.extend({"id": id}, {m: 'yi_order', a: 'wuliu'}), function (resp) {
                    if(resp.status == 1){
                        $('.js-pop').removeClass('none');
                        $('.js-pop .col-xs-12').html(resp.data);
                        //mask.success(resp.data);
                    } else {
                        mask.error(resp.msg);
                    }
                });
            });
            $('.js-pop .popup-container').click(function(){
                $('.js-pop').addClass('none');
            });
        },
        page_addr: function () {
            var _this = this;
            utils.cate_select({field:'J_cate_id',select:'J_cate_select'});
            $('.fuck').click(function(){
                var frm = '#addressFrom';
                var name = $(frm).find('input[name=addr_name]').val();
                var tele = $(frm).find('input[name=addr_tele]').val();
                var cardid = $(frm).find('input[name=addr_cardid]').val();
                var zipcode = $(frm).find('input[name=addr_zipcode]').val();
                var c_id = $('#J_city_id').val();
                var address = $(frm).find('input[name=addr_address]').val();
                var remark = $(frm).find('input[name=addr_remark]').val();
                var yi_id = $(frm).find('input[name=yi_id]').val();
                if(name == ''){
                    mask.error('收货人不能为空');
                    $("[name='addr_name']").focus(); 
                    return false;
                }
                if(tele == ''){
                    mask.error('手机号码不能为空');
                    $("[name='addr_tele']").focus(); 
                    return false;
                }
                if(zipcode == ''){
                    mask.error('邮政编码不能为空');
                    $("[name='addr_zipcode']").focus(); 
                    return false;
                }
                if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tele))){ 
                    mask.error("手机号格式不正确"); 
                    $("[name='addr_tele']").focus(); 
                    return false; 
                } 
                /*if(c_id == ''){
                    mask.error('请选择省份城市');
                    return false;
                }*/
                if(address == ''){
                    mask.error('详细地址不能为空');
                    $("[name='addr_address']").focus(); 
                    return false;
                }

                utils.ajaxPost(_.extend({'addr_name':name, 'addr_tele': tele, 'addr_zipcode': zipcode, 'c_id': c_id, 'addr_address': address, 'addr_cardid': cardid, 'addr_remark': remark, 'yi_id': yi_id}, {m: 'yi_order', a: 'addr'}), function (resp) {
                    mask.success(resp.msg);
                    setTimeout(
                        _this.redirect(_.U({m: 'yi_order', a: 'index'}), 1)
                    ,1000);
                });
            });
        },
    });
});